home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
tcqbsnip.zip
/
SORT.BAS
< prev
next >
Wrap
BASIC Source File
|
1997-06-20
|
1KB
|
44 lines
' SORT.BAS
' by Tika Carr
' (date unknown)
'
' Donated to the public domain
' No warranties or guarantees are expressed or implied.
'
' Purpose: Two routines to sort numbers or strings. Uses the Bubble Sort
' algorythm.
DECLARE SUB numsort (a%())
DECLARE SUB strsort (a$())
DEFINT A-Z
'sort numbers: numsort
DIM a(5)
a(1) = 46: a(2) = 4: a(3) = 100: a(4) = 12: a(5) = 89
PRINT "Unsorted: ": FOR i = 1 TO 5: PRINT a(i), : NEXT: PRINT
numsort a()
PRINT "Sorted: ": FOR i = 1 TO 5: PRINT a(i), : NEXT: PRINT
'sort strings: strsort
REDIM a$(5)
a$(1) = "cat": a$(2) = "antelope": a$(3) = "dog"
a$(4) = "bear": a$(5) = "buffalo"
PRINT "Unsorted: ": FOR i = 1 TO 5: PRINT a$(i), : NEXT: PRINT
strsort a$()
PRINT "Sorted: ": FOR i = 1 TO 5: PRINT a$(i), : NEXT: PRINT
END
SUB numsort (a())
FOR c = 1 TO UBOUND(a): FOR d = 1 TO UBOUND(a) - 1
IF a(d) > a(d + 1) THEN SWAP a(d), a(d + 1)
NEXT d, c
END SUB
SUB strsort (a$())
FOR c = 1 TO UBOUND(a$): FOR d = 1 TO UBOUND(a$) - 1
IF a$(d) > a$(d + 1) THEN SWAP a$(d), a$(d + 1)
NEXT d, c
END SUB